package com.example.springbootredis.repository;



import com.example.springbootredis.entiy.Classroom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ClassroomRepository extends JpaRepository<Classroom, Long> {

    // 检查教室编号是否已存在
    boolean existsByClassroomNo(String classroomNo);

    // 检查教室名称是否已存在
    boolean existsByClassroomName(String classroomName);

    // 根据校区查询
    List<Classroom> findByCampus(String campus);

    // 根据教室名称模糊查询
    List<Classroom> findByClassroomNameContaining(String classroomName);

    // 根据校区和教室名称模糊查询
    List<Classroom> findByCampusAndClassroomNameContaining(String campus, String classroomName);

    // 检查教室编号是否已存在（排除当前ID）
    @Query("SELECT COUNT(c) > 0 FROM Classroom c WHERE c.classroomNo = :classroomNo AND c.id != :id")
    boolean existsByClassroomNoAndIdNot(@Param("classroomNo") String classroomNo, @Param("id") Long id);

    // 检查教室名称是否已存在（排除当前ID）
    @Query("SELECT COUNT(c) > 0 FROM Classroom c WHERE c.classroomName = :classroomName AND c.id != :id")
    boolean existsByClassroomNameAndIdNot(@Param("classroomName") String classroomName, @Param("id") Long id);
}